package chixing.day13.work;

public class Cup implements MyCompare{
    private int id;          // 编号
    private String name;     // 名称
    private double price;    // 价格
    private String origin;   // 产地
    private String color;    // 颜色
    private double capacity; // 容量
    public Cup() {
    }
    public Cup(int id, String name, double price, String origin, String color, double capacity) {
        super();
        this.id = id;
        this.name = name;
        this.price = price;
        this.origin = origin;
        this.color = color;
        this.capacity = capacity;
    }


    @Override
    public int compare(Object anotherObj) {
        Cup other = (Cup) anotherObj;
        int nameCompare = this.name.compareTo(other.name);
        if (nameCompare != 0) {
            return nameCompare;
        }

        // 2. 名称相等则比较价格
        if (this.price > other.price) {
            return 1;
        } else if (this.price < other.price) {
            return -1;
        }

        // 3. 价格相同则比较编号
        if (this.id > other.id) {
            return 1;
        } else if (this.id < other.id) {
            return -1;
        }

        // 4. 编号相同，视为同一个对象
        return 0;
    }
}
